//��ת
var app=angular.module('myApp',['ng','ngRoute']);
app.config(function($routeProvider){
    $routeProvider
        .when('/myMain',
        {templateUrl:'tpl/main.html',
            controller:'main'
        })
        .when('/myCompany',
        {templateUrl:'tpl/mycompany.html'})
        .when('/myStart',
        {templateUrl:'tpl/start.html'})
        .when('/myRelate',
        {templateUrl:'tpl/relate.html'})
        .when('/myAgency',
        {templateUrl:'tpl/agency.html'})
        .when('/myNew',
        {templateUrl:'tpl/new.html'})
        .when('/myRange',
        {templateUrl:'tpl/range.html'})
        .when('/myJoin',
        {templateUrl:'tpl/join.html'})
        .when('/myTel',
        {templateUrl:'tpl/tel.html'})
        .when('/myEnroll',
        {templateUrl:'tpl/enroll.html',controller:"sub"})
        .when('/myMessage',
        {templateUrl:'tpl/message.html',controller:"mess"})
       .otherwise({redirectTo:'/myCompany'})
})
//顶部

app.controller("ctrl",["$scope","$location",function($scope,$location){
    $scope.jump=function(a){
        $location.path(a);
    }
}])
//导航条
app.controller('nn',['$scope',"$location",function($scope,$location){
    $('a').click(function(e){
        e.preventDefault();
    })
    var site=window.location.hash.slice(2);
    (function () {
        console.log($('#menu>ul>li'));
        $.each($('#menu>ul>li'), function () {
            $(this).find('a').attr('href') == site && ($(this).toggleClass('bg-modena'));
        })
    })()
}])
//顶部
app.controller('dn',['$scope',function($scope){
    $('.banner').on('click','div>ul>li>a', function (e) {
        e.preventDefault();
    })
}])
//主页导航条
app.controller('dd',['$scope','$location',function($scope,$location){
    $('.container-nei').on('click','p a', function (e) {
        e.preventDefault();
    })
    var site=window.location.hash.slice(2);
    switch (site){
        case 'myMain':
            break;
        case 'myRelate':
            $('.weizhi>span').html('关于我们');
            break;
        case 'myCompany':
            $('.weizhi>span').html('公司风采');
            break;
        case 'myAgency':
            $('.weizhi>span').html('茶经解读');
            break;
        case 'myNew':
            $('.weizhi>span').html('新闻中心');
            break;
        case 'myRange':
            $('.weizhi>span').html('服务范围');
            break;
        case 'myJoin':
            $('.weizhi>span').html('招聘信息');
            break;
        case 'myMessage':
            $('.weizhi>span').html('客户留言');
            break;
        case 'myTel':
            $('.weizhi>span').html('联系我们');
            break;
    }
}])
//主页面
app.controller('main',['$scope','$location','$http',function($scope,$location,$http){
    $('.banner').on('click','li.sum>a', function (e) {
        e.preventDefault();
    })
    $(function(){
        $http
            .get('data/main.php')
            .success(function(data){
                console.log(data);
                $scope.lists=data[0];
                $scope.mainTops=data[1];
                $scope.mainTpxws=data[2];
                $scope.yxLunbos=data[3];
                $scope.yxContents=data[4];
                $scope.rqContents=data[5];
                $scope.mainButtoms=data[6];
            })
    })
    $(document).ready(function() {
        $('.carousel').carousel({
            interval: 2000
        })
    });
}])
//注册页面
app.controller('sub',['$scope','$http',function($scope,$http){
    $scope.fun=function(){
         $scope.args={
            uset:$scope.uset,
            uname:$scope.uname,
            uphone:$scope.uphone,
            upwd:$scope.upwd
        };
        console.log($.param($scope.args));
        var args= $.param($scope.args);
        $http.get('data/user_add.php?'+args)
            .success(function(data){
                console.log(1111);
                alert('注册成功');
                $('.bg-8').css('background-position','0 -450px');
                $scope.uset='';
                $scope.uname='';
                $scope.uphone='';
                $scope.upwd='';
            })
            .error(function(){
                alert('注册失败')
            })
    }
}])
app.controller('mess',['$scope','$http',function($scope,$http){
    $scope.mess=function(){
        $scope.arr={
            name:$scope.name,
            content:$scope.content
        }
        console.log($scope.arr);
        var arr= $.param($scope.arr);

        console.log(arr);
        $http.get('data/message_add.php?'+arr)
            .success(function(){
                $scope.name='';
                $scope.content='';
                fun1();
            })

    }
    var fun1=function(){
        $http.get('data/message.php')
            .success(function(data){
                $(data).each(function(i){
                    data[i].messageTime=new Date(parseFloat(data[i].messageTime)).toLocaleString()
                })
                $scope.lists=data;
            })
    }
    fun1();

}])
//轮播

